//ex9_4.cpp
#include <iostream>
#include "sales.h"

using namespace std;
namespace SALES
{
    void setSales(Sales &s, const double ar[], int n)
    {
        double sum1 = 0.0;
        int i, cnt = 0;
        for (i = 0; i < n && i < 4; i++)
        {
            s.sales[i] = ar[i];
            sum1 += s.sales[i];
        }
        cnt = i;
        s.average = sum1 / n;
        s.max = s.sales[0];
        s.min = s.sales[0];
        for (i = 1; i < cnt; i++)
        {
            if (s.max < s.sales[i])
                s.max = s.sales[i];
            if (s.min > s.sales[i])
                s.min = s.sales[i];    
        }

        if (n < 4)
        {
            for (int j = n; j < 4; j++)
                s.sales[j] = 0;
        }
    }
    void setSales(Sales &s)
    {
        double sum1 = 0.0;
        cout << "Enter 4 sales quarters:\n";
        for (int i = 0 ; i < QUARTERS; i++)
        {
            cout << "[" << i + 1 << "]: ";
            cin >> s.sales[i];
            sum1 += s.sales[i];
            if (i == 0)
            {
                s.max = s.sales[i];
                s.min = s.sales[i];
            }
            else 
            {
                if (s.max < s.sales[i])
                    s.max = s.sales[i];
                if (s.min > s.sales[i])
                    s.min = s.sales[i]; 
            }
            s.average = sum1 / QUARTERS;
        }
    }
    void showSales(const Sales &s)
    {
        cout << "Enter 4 sales quarters:\n";
        for (int i = 0 ; i < QUARTERS; i++)
        {
            cout << s.sales[i] << "\t";
        }
        cout << "\n";
        cout << "average = " << s.average << "\n";
        cout << "max = " << s.max << "\n";
        cout << "min = " << s.min << "\n";
    }
}
